!function(t){peepso=peepso||{},peepso.notification=new(function(r){var i=+peepsodata.sse;function t(){var i=this;function e(){setTimeout(function(){i.start()},3e3)}r(function(){_.defer(function(){var t=r("#peepso-wrap").length,i=r("#wpadminbar").find(".psnotification-toggle").length;if(t||i){e()}})});peepso.observer.addAction("notification_start",e);peepso.observer.addAction("notification_titlebar",function(t){i._update_titlebar(t)},10,1)}return t.prototype={_get_latest_interval:+peepsodata.get_latest_interval||3e4,_get_latest_count:function(){peepso.disableAuth().disableError().postJson("notificationsajax.get_latest_count",null,r.proxy(function(t){var a;t.success&&!t.session_timeout&&(a=0,r.each(t.data,function(t,i){var e,o,s=r("."+t),n=Math.max(0,i.count);a+=n,s.length&&(e=+(o=s.find(".ps-js-counter")).eq(0).text(),o.length&&e!==n&&(o.html(n).css("display",0"),this.popover_list=a("
").css({maxHeight:"40vh",overflow:"auto"}),this.popover_list.bind("mousewheel",a.proxy(function(t,i){var e=a(t.currentTarget);0"),this.popover_header.addClass("ps-popover-header app-box-header").append(this.opts.header).append("
"),this.popover.append(this.popover_header)),this.popover.append(this.popover_list),this.popover_list.addClass("ps-notifications ps-notifications--empty"),this.popover.addClass("ps-popover app-box").hide(),this.opts.paging&&this.init_pagination();var e,i=this.opts.view_all_link,o=this.opts.view_all_text;i&&(o=_.isArray(o)?o:[o],i=_.isArray(i)?i:[i],e=[!1,!1,"50%","33%","25%"][i.length],i=_.map(i,function(t,i){return['",o[i],""].join("")}),this.popover_footer=a(''),this.popover_footer.append(i.join("")),this.popover_footer.appendTo(this.popover)),this.popover_list.on("mousedown.ps-notification",".ps-js-notification a",a.proxy(function(i){var e=a(i.currentTarget),o=e.closest(".ps-js-notification");+o.data("unread")&&(3===i.which||i.ctrlKey||i.altKey||(2===i.which||i.metaKey||i.shiftKey||e.on("click",function(t){t.preventDefault(),t.stopPropagation()}),o.css("opacity",.5),o.removeClass("ps-notification--unread"),peepso.notification.markAsRead(o.data("id")).done(a.proxy(function(){var t=+o.closest(".ps-js-notifications").find(".ps-js-counter").text();o.css("opacity",""),o.data("unread",0),1!==i.which||i.metaKey||i.shiftKey||(e.off("click"),e[0].click()),a(".ps-js-notifications").find(".ps-js-counter").html(t-1).css("display",1
");e.html(i).hide(),e.appendTo(n.popover_list).fadeIn("slow")}),a(s).trigger("notifications.shown",[a.extend(s,this)]),a(document.body).hasClass("wp-admin")&&a(s).find("a").attr("target","_blank"),this.popover_list.toggleClass("ps-notifications--empty",0===this.popover_list.find(".ps-notification__wrapper").length)},this.show=function(){this.popover.slideToggle({duration:"fast",start:function(){n.popover.position({my:"right top",at:"bottom",of:a("i",s),using:function(t,i){"right"===i.horizontal?(a(this).removeClass("flipped"),t.left+=40):(a(this).addClass("flipped"),t.left-=40),t.top+=10,a(this).css(t)}})},done:function(){a(document).on("mouseup.notification_click",function(t){a(s).is(t.target)||0!==a(s).has(t.target).length||(n.popover.hide(),a(document).off("mouseup.notification_click"))})}})},this.init_pagination=function(){this.popover_list.on("scroll",function(){n._content_is_fetched&&a(this).scrollTop()+a(this).innerHeight()>=a(this)[0].scrollHeight&&(n._content_is_fetched=!1,n.load_page(function(){n._notifications&&_.isEmpty(n._notifications)?n.popover_list.off("scroll"):n.popover_list.trigger("scroll")}))})},this.load_page=function(t){if(!1===this._content_is_fetched){var e=this.popover_list.nextAll(".ps-popover-error"),i=this.popover_list.nextAll(".ps-popover-loading");e.length&&e.remove(),i.length||(i=a("
"),this.popover_list.after(i)),this.fetch_stop(),setTimeout(function(){n.fetch(function(){i.remove(),n._errors&&(e=a("
"),a.each(n._errors,function(t,i){a("
").html(i).appendTo(e)}),n.popover_list.after(e)),n.render(),typeof t==typeof Function&&t(),"function"==typeof n.opts.after_load&&n.opts.after_load.apply(n)})},500)}},this.clear_cache=function(){this.popover_list.find(".ps-notification__wrapper").remove(),this.popover.hide(),this.opts.request.page=1,this._content_is_fetched=!1},this.init(t),a(s).on("click",this.onClick),this}a.fn.psnotification=function(i){return this.each(function(){if(a.data(this,"plugin_psnotification")){var t=a.data(this,"plugin_psnotification");if(_.isFunction(t[i]))return t[i].call(t)}else a.data(this,"plugin_psnotification",new e(this,i))})},peepso.observer.addAction("notification_clear_cache",function(t){a("."+(t=t||"ps-js-notifications")).psnotification("clear_cache")},10,1)}(jQuery),jQuery(function(t){});